package com.kundi.dooradmin.controller;

import com.kundi.dooradmin.entity.Success;
import com.kundi.dooradmin.service.SuccessService;
import com.kundi.dooradmin.util.MapUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * Author 赵恒
 * Date 2020/6/24
 */
@Controller
@RequestMapping("/success")
public class SuccessController {
    @Resource
    SuccessService successService;

    @RequestMapping("/getAll")
    @ResponseBody
    public List<Success> getAll() {
        return successService.getAll();
    }

    @RequestMapping("/getSuccessById")
    @ResponseBody
    public Success getSuccess(Integer id) {
        return successService.getSuccessById(id);
    }

    @RequestMapping("/insert")
    @ResponseBody
    public Map<String, String> insert(Success success) {
        Integer i = successService.insert(success);
        if(i > 0) {
            return MapUtil.responseMap("添加成功", "true");
        } else {
            return MapUtil.responseMap("添加失败", "false");
        }
    }

    @RequestMapping("/update")
    @ResponseBody
    public Map<String, String> update(Success success) {
        Integer i = successService.update(success);
        if(i > 0) {
            return MapUtil.responseMap("修改成功", "true");
        } else {
            return MapUtil.responseMap("修改失败", "false");
        }
    }


}
